/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bitcore.mappings;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author julio jw0rmc
 */
public class TaxistaHelper {
    Session session=null;
    
    public TaxistaHelper()
    {
    this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    public Taxista getTaxistaPorId(String id){
    Taxista taxista = null;
    try {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
        org.hibernate.Transaction tx = session.beginTransaction();
        this.session.clear(); 
        Query q = session.createQuery ("from Taxista as taxista where taxista.id='"+id+"'");
        taxista =(Taxista)  q.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return taxista;
    }
    
    public List<Taxista> getTaxistasPorExtent(double miny,double maxy,double minx,double maxx){
    List<Taxista> taxista = null;
    try {
        
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
        org.hibernate.Transaction tx = session.beginTransaction();
        this.session.clear();
        Query q = session.createQuery ("from Taxista where (lat_actual <"+maxy+" AND lat_actual>"+miny+") AND (lon_actual < "+maxx+" AND lon_actual>"+minx+")");
        taxista =(List<Taxista>)  q.list();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return taxista;
    }
    

    public Taxista actualizaTaxistaById(String id,double lat,double lon){
    Taxista taxista = null;
    try {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
        org.hibernate.Transaction tx = session.beginTransaction();
        this.session.clear();
        Query q = session.createQuery ("from Taxista as taxista where taxista.id='"+id+"'");
        taxista =(Taxista)  q.uniqueResult();
        taxista.setLatActual(lat);
        taxista.setLonActual(lon);
        session.update(taxista);
        tx.commit();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return taxista;
    }
    

    
}
